const router = require('./router');
const url = require('url');



router.get('/list', (req, res) => {
    const params = url.parse(req.url, true).query;
    console.log('params', params);
    const {
        uid
    } = params;
    console.log('uid', uid)
    const user = [{
            uid: "1",
            uname: '张三',
            age: 20
        },
        {
            uid: "2",
            uname: '李四',
            age: 21
        },
        {
            uid: "3",
            uname: '王五',
            age: 22
        }
    ];
    const ids = user.map(m => m.uid);
    console.log('ids', ids);
    const flag = ids.indexOf(uid) != -1;
    if (JSON.stringify(params) == "{}") {
        res.json({
            code: "0",
            data: user,
            msg: '成功',
            success: true
        })

    } else {
        if (flag) {
            res.json({
                code: "0",
                data: user.filter(f => f.uid == uid),
                msg: '成功',
                success: true
            })
        } else {
            res.json({
                code: "0",
                data: [],
                msg: '成功',
                success: true
            })
        }

    }

});

module.exports = router;